package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.Psychometric;
import com.hl.sfzy.service.PsychometricService;
import com.hl.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 1. @ClassDescription:
 * 2. @ClassName PsychometricController
 * 3. @Description TODO
 * 4. @Author: YuKunXu
 * 5. @Date: 2024年01月12日 19:31
 * 6. @Project: sfzy
 * 7. @Version 1.0
 */
@CrossOrigin
@RestController
@RequestMapping("/psychometric")
public class PsychometricController {
    @Autowired
    private PsychometricService psychometricService;
    @PostMapping("/add")
    public Result add(@RequestBody Psychometric psychometric) throws Exception {
        psychometricService.add(psychometric);
        return Result.success();
    }

    /**
     * 编辑
     */
    @PutMapping("/edit")
    public Result edit(@RequestBody Psychometric psychometric) {
        psychometricService.edit(psychometric);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable Integer id) {
        psychometricService.remove(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/remove")
    public Result removeBatch(Integer[] ids) {
        System.out.println(ids);
        psychometricService.removeBatch(ids);
        return Result.success();
    }

    /**
     * 单条查询
     */
    @GetMapping("/find/{id}")
    public Result findById(@PathVariable Integer id) {
        return Result.success(psychometricService.findById(id));
    }

    /**
     * 分页查询
     */
    @GetMapping("/find")
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                           Psychometric psychometric) {
        return Result.success(psychometricService.findPage(pageNum, pageSize, psychometric));
    }
}